import $ajax from '../ajax'

/**
 * @desc 在实际开发中，您可以将 baseUrl 替换为您的请求地址前缀；
 *
 * 已将 $apis 挂载在 global，您可以通过如下方式，进行调用：
 * $apis.example.getApi().then().catch().finally()
 *
 * 备注：如果您不需要发起请求，删除 apis 目录，以及 app.ux 中引用即可；
 */
//测试域名
const baseUrl = process.env.NODE_ENV == 'development' ? 'http://mmdev.yitanwangluo.cn/api/' : 'https://xj.yitanwangluo.cn/api/'
// const clBaseUrl = process.env.NODE_ENV == 'development' ? 'http://cldevapi.senbowl.top/api/' : 'https://clapi1.senbowl.top/api/'
const clBaseUrl = process.env.NODE_ENV == 'development' ? 'http://cldevapiold.senbowl.top/api/' : 'https://clapi1.senbowl.top/api/'
var appDef = null

/**
 * 游客登录
 */
const quickUrl = "member/autoLogin"
// 签到记录查询
const signLog = "signInLog/getsigndate"
// 签到
const signAdd = "signInLog/add"
// 任务记录查询
const taskLog = "taskLog/log"
// 领取任务
const taskAdd = "taskLog/add"
// 基础设置
const setBase = "site/view"

// 记事-新增
const addEvent = "notepad/add"
// 记事-修改
const modifyEvent = "notepad/update"
// 记事-详情
const eventDetail = "notepad/view"
// 记事-列表
const eventList = "notepad/index"
// 记账-新增
const addCharge = "chargeUp/add"
// 记账-修改
const modifyCharge = "chargeUp/update"
// 记账列表
const chargeList = "chargeUp/index"
// 记账删除
const chargeDelete = "chargeUp/delete"
// 记事删除
const eventDelete = "notepad/delete"

/**
* 投诉提交
*/
const submitComplaint_url = "usercomplaint/add"
function getAppDefPageName() {
  if (appDef) {
    return appDef.pageCodeInfo.pathCurUrl
  } else {
    return '默认页面'
  }
}

export default {
  setAppDef(obj) {
    if (obj) {
      appDef = obj
    }
  },
  taskAdd(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${taskAdd}`, data, getAppDefPageName())
  },
  taskLog(data) {
    return $ajax.get(`${baseUrl}${taskLog}`, data, getAppDefPageName())
  },
  signAdd(data) {
    return $ajax.post(`${baseUrl}${signAdd}`, data, getAppDefPageName())
  },
  signLog(data) {
    return $ajax.get(`${baseUrl}${signLog}`, data, getAppDefPageName())
  },
  login(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${quickUrl}`, data, getAppDefPageName())
  },
  setBase(data) {
    return $ajax.get(`${baseUrl}${setBase}`, data, getAppDefPageName())
  },
  complaintApi(data) {
    return $ajax.post(`${clBaseUrl}${submitComplaint_url}`, data, getAppDefPageName());
  },
  addEvent(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${addEvent}`, data, getAppDefPageName())
  },
  modifyEvent(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${modifyEvent}`, data, getAppDefPageName())
  },
  eventDetail(data) {
    return $ajax.get(`${baseUrl}${eventDetail}`, data, getAppDefPageName())
  },
  eventList(data) {
    return $ajax.get(`${baseUrl}${eventList}`, data, getAppDefPageName())
  },
  addCharge(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${addCharge}`, data, getAppDefPageName())
  },
  modifyCharge(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${modifyCharge}`, data, getAppDefPageName())
  },
  chargeList(data) {
    return $ajax.get(`${baseUrl}${chargeList}`, data, getAppDefPageName())
  },
  chargeDelete(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${chargeDelete}`, data, getAppDefPageName())
  },
  eventDelete(data) {
    data.complainSure = true
    return $ajax.post(`${baseUrl}${eventDelete}`, data, getAppDefPageName())
  }

}